/* eslint-disable prettier/prettier */
import Vue from "vue";
import VueRouter from "vue-router";
import ElementUI from "element-ui";
// import LoginView from "../views/HomeView.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "login",
    component: () =>
      import(/* webpackChunkName: "about" */ "@/views/LoginView.vue"),
  },
  {
    path: "/home",
    name: "home",
    redirect: "/home/1-1",
    component: () =>
      import(/* webpackChunkName: "about" */ "@/views/HomeView.vue"),
    children: [
      // 首页路由
      {
        path: "/home/1-1",
        component: () => import("@/views/homepage/AnalysisPage.vue"),
      },
      {
        path: "/home/1-2",
        component: () => import("@/views/homepage/WorkBench.vue"),
      },
      // 交易管理路由
      {
        path: "/home/2-1", //订单管理
        component: () => import("@/views/transaction/OrderForm.vue"),
      },
      {
        path: "/home/2-2", //评价中心
        component: () => import("@/views/transaction/AssessmentCenter.vue"),
      },
      {
        path: "/home/2-3", //试用页
        component: () => import("@/views/transaction/newpage.vue"),
      },
      // 商品管理
      {
        path: "/home/3-1", //商品列表
        component: () => import("@/views/commodity/ProductList.vue"),
      },
      {
        path: "/home/3-2", //创建商品
        component: () => import("@/views/commodity/CommodityCreate.vue"),
      },
      // 营销中心
      {
        path: "/home/4-1", //优惠券设置
        component: () =>
          import("@/views/marketing/DiscountCoupon/DiscountCoupon.vue"),
      },
      {
        path: "/home/4-2", //活动报名
        component: () =>
          import("@/views/marketing/ActivityRegister/ActivityRegister.vue"),
      },
      {
        path: "/home/4-3", //mock数据
        component: () =>
          import("@/views/marketing/ActivityRegister/MockApi.vue"),
      },
      // 数据统计
      {
        path: "/home/5-1", //整体概览
        component: () => import("@/views/datastatistics/AggregateData.vue"),
      },
      {
        path: "/home/5-2", //数据分析
        component: () => import("@/views/datastatistics/DataAnalysis.vue"),
      },
      // 店铺管理
      {
        path: "/home/6-1", //店铺信息
        component: () => import("@/views/shop/ShopInfo.vue"),
      },
      {
        path: "/home/6-2", //店铺装修
        component: () => import("@/views/shop/ShopDecoration.vue"),
      },
      
    ],
  },
];
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});
// 判断登录过期
router.beforeEach((to, from, next) => {
  if (to.path === "/") {
    next();
  } else {
    let token = localStorage.getItem("token");
    if (token === null || token === "") {
      ElementUI.Message.error("登录过期，请重新登录");
      next("/");
    } else {
      next();
    }
  }
});
export default router;
